import java.util.Deque;
import java.util.LinkedList;

public class IsCompleteTree {
    // 判断是不是完全二叉树
    // https://www.nowcoder.com/practice/8daa4dff9e36409abba2adbe413d6fae?tpId=295&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3DSQL%25E7%25AF%2587%26topicId%3D295
    public boolean isCompleteTree (TreeNode root) {
        // write code here
        if (root == null) {
            return true;
        }
        Deque<TreeNode> deque = new LinkedList<>();
        deque.add(root);
        boolean flag = false;
        while (!deque.isEmpty()) {
            TreeNode node = deque.pollFirst();
            if (node == null) {
                flag = true;
                continue;
            } else {
                if (flag) {
                    return false;
                }
                deque.addLast(node.left);
                deque.addLast(node.right);
            }
        }
        return true;
    }
}
